/**
 * author:龚佳新  
 * date:2013-11-27
 * 资产结构模型 方法全部抽取 为目前最精简模式
 */
Cnbi.model.Profita= function(params) {
   Cnbi.model.BaseSliderAndProgress.call(this,params); 
   var  button_array = [{ renderTo : 'BQ',id:'bqId', text : "本月情况",query:3, handler : function() {updataData(this,3);}},{ renderTo : 'LJ',id:'ljId', text : "累计情况",query:4,handler : function() {updataData(this,4);} }];
   var defaults = this.defaults;
   var scope = this,domArray = params["domArray"];
   this.initPage=function(){
	      if(!scope.flag){//alert("子类的initPage");
	      		CnbiSoft.setCurrentRenderer("JavaScript");
	      		//createBtn();
	    	}

	   setFormula(false);
	   scope.setSliderValue(params.slider_array, scope.datas, "input");
	   scope.setProgressValue(params.progress_array,scope.datas, "span");
	   this.initChart(true);
	   
	   if(!scope.flag){
	        updataData();
	       }
	     	
    }
    
    function updataData(obj,a) {
    	var msg = "利润情况分析【"+scope.defaults["params"]["year"]+"---"+scope.defaults["params"]["month"]+"---"+scope.defaults["params"]["unit"]+"】";
    	if(obj){
    	  	msg+=obj.text;
    	   	//scope.defaults["params"]["query"] = a;
    	   	scope.init();
    	   	 obj.disable();
    	   	if(obj.getId()=="bqId"){
    	   	    setBtnEnable("ljId");
    	   	}else{
    	   	  	setBtnEnable("bqId");
    	   	}
    	}else{
    	  //msg+=Ext.getCmp("bqId").text;
    	  //Ext.getCmp("bqId").disable();
    	}
    }
    
    function setBtnEnable(id){
        Ext.getCmp(id).enable();
    }
    
    function createBtn() {
        for (var i = 0; i < button_array.length; i++) {
            new Ext.Button({
            	        id:button_array[i]["id"],
                        text : button_array[i]["text"],
                        renderTo : button_array[i]["renderTo"],
                        width : 100,style : {marginTop : "50px"},height : 50,
                        handler : button_array[i]["handler"]
            });
        }
    };
    this.initChart=function(action){   	  
    	  var pieChart = new Cnbi.model.Chart(getPieChartObj());
    	  pieChart.createSingleSeriesChart();
    	   var cbfyv = "cbfyvId";//params["judgeObj"]["cbfyv"];
    	  		 var obj={domId:domArray[0],datas:scope.datas[params["judgeObj"]["cbfyv"]]-0,range:scope.industyParams[cbfyv],title:'成本费用利用率'};                                                                                                                                                                                                                                                                            
    	      var angleChart = new Cnbi.model.Chart({swf:"AngularGauge",domId:cbfyv});
    	      angleChart.createAngleChart();
    	 
      	   /* if(action){ 
      		 new Cnbi.model.Chart(getAngularGaugeObj(obj));
      		  };*/
    	  }
   	  
    function getPieChartObj(){
    	return {chartType:1,//图表类型 ：0为单值数据图表;1为多单数据图表;2为多系数据图表  Pyramid
	            swf:"Pyramid",//这个就不用说了吧！  //AngularGauge.swf  Pie2d
	           // datas:[{index0:"5656",index1:"",index2:""},[{index0:"2332",index1:"营业成本",index2:scope.datas[params["judgeObj"]["yycb"]]},{index0:"525",index1:"销售费用",index2:scope.datas[params["judgeObj"]["xsfy"]]},{index0:"565",index1:"财务费用",index2:scope.datas[params["judgeObj"]["cwfy"]]},{index0:"2323",index1:"管理费用",index2:scope.datas[params["judgeObj"]["glfy"]]},{index0:"8989",index1:"税金附加",index2:scope.datas[params["judgeObj"]["yysjjfj"]]}]],//显示的数据  注意：规定的数据解析格式
	            value:[125.36,80.63,70.89,56.39,63.02],
	            label:["营业成本","销售费用","财务费用","财务费用"," 管理费用","税金附加"],//销售费用  财务费用  财务费用 管理费用 税金附加
	            domId:domArray[1],//渲染的dom节点
	           // color:["1C86EE","EEC900","6B8E23","9400D3","FF0000"], //颜色
	           // percent:true,
	            chart:{caption:"成本费用结构图"}
	          	//attributes:'caption="成本费用结构图" formatNumberScale="0" chartTopMargin="0" chartLeftMargin="5" showBorder="1"  borderColor="dddddd"  bgColor="ffffff" bgAlpha="100" showValues="0"'
	          	}
    };	    
    var upperLimit=0.00;
    function getAngularGaugeObj(params){
     	var range = params["range"];upperLimit=range["excellent"]-0;	
     	if((params["datas"]-0)>upperLimit){
     		upperLimit = params["datas"]-0;
     	}
        return {chartType:0,//图表类型 ：0为单值数据图表;1为多单数据图表;2为多系数据图表
	            swf:"AngularGauge",//这个就不用说了吧！  //AngularGauge.swf
	            datas:params["datas"],//显示的数据  注意：规定的数据解析格式  numberSuffix="%"
	            domId:params["domId"],//渲染的dom节点
	            attributes:'bgAlpha="1" lowerLimit="'+range["average"]+'" upperLimit="'+upperLimit+'" lowerLimitDisplay="差" upperLimitDisplay="好" numberSuffix="%" showValue="1" palette="1" showBorder="0"',
	            color:["FF0000","EEC900","00CD00"], //颜色good 
	          	colorRange:[range["lowers"],range["average"],range["good"],upperLimit],//chartType==0时才有此属性
	          	width:"82%",height:"28%"};
    };   
    
    this.updataInputAfter=function(id ,value,datas ){		
		setFormula(true); 
	};
	
	function setFormula(action) {
		console.dir(scope.datas[params["judgeObj"]["cbfyv"]]);
		scope.initBefore();
		var  chartId=domArray[0].toString()+domArray[2].toString();
	    if(getChartFromId(chartId)){
            var tempData = scope.datas[params["judgeObj"]["cbfyv"]]-0;
	        if((scope.datas[params["judgeObj"]["cbfyv"]]-0)> upperLimit){
	    		tempData =upperLimit;
	       }
	       getChartFromId(chartId).setData(1,tempData);
	    }	       	   	      
	} 
   	scope.init();
}
